package diagramobjects;

import java.awt.Graphics;
import java.util.Vector;

import utils.Point;
import utils.Color;

import program.PaintObjects;

public class Actor extends DiagramObject
{
	private Text Name;
	private Line LeftLeg;
	private Line RightLeg;
	private Line Hands;
	private Line Torso;
	private Elipse Head;
	


	@Override
	public Boolean Selection(Integer selLeft, Integer selRight, Integer selTop, Integer selBottom)
	{	
		
		//System.out.println("ACTOR SELECTION");
		Integer Left = getPositionX();
		Integer Right = getPositionX() + getWidth();
		Integer Top = getPositionY();
		Integer Bottom = getPositionY() + getHeight();
        // aaa xls
			
		return (Left < selRight) && 
					(Right > selLeft) &&
					(Top < selBottom) &&
					(Bottom > selTop);
					
	}
	
	
	/*public Actor(Text name, Line leftLeg, Line rightLeg, Line hands,
			Line torso, Elipse head)
	{
		super();
		Name = name;
		LeftLeg = leftLeg;
		RightLeg = rightLeg;
		Hands = hands;
		Torso = torso;
		Head = head;
	}
*/
	public Actor(String name, Integer x, Integer y)
	{
		super();
		Name = new Text("Actor", new Point(x, y), new Color(0,11,255), 10);
		LeftLeg = new Line(x, y);
		RightLeg = new Line(x, y);
		Hands = new Line(x, y);
		Torso = new Line(x, y);
		Head = new Elipse(x, y);
		
	}
	
	public Integer getWidth()
	{
		return Hands.getEndX() - Hands.getBeginX();
	}
	
	public Integer getHeight()
	{
		return LeftLeg.getBeginY() - Head.getFromPoint().getY(); 
	}
	
	public Integer getPositionX()
	{
		return Hands.getBeginX();
	}
	
	public Integer getPositionY()
	{
		return Head.getFromPoint().getY();
	}
	
	
	


	@Override
	public void Draw(Graphics g, PaintObjects po)
	{
		// TODO Auto-generated method stub
		po.DrawActor(g, this);
	}

	@Override
	public void DrawSelection(Graphics g, PaintObjects po)
	{
		// TODO Auto-generated method stub
		po.DrawActorSelection(g, this);
	}
	
	public Text getName()
	{
		return Name;
	}

	public void setName(Text name)
	{
		Name = name;
	}

	public Line getLeftLeg()
	{
		return LeftLeg;
	}

	public void setLeftLeg(Line leftLeg)
	{
		LeftLeg = leftLeg;
	}

	public Line getRightLeg()
	{
		return RightLeg;
	}

	public void setRightLeg(Line rightLeg)
	{
		RightLeg = rightLeg;
	}

	public Line getHands()
	{
		return Hands;
	}

	public void setHands(Line hands)
	{
		Hands = hands;
	}

	public Line getTorso()
	{
		return Torso;
	}

	public void setTorso(Line torso)
	{
		Torso = torso;
	}

	public Elipse getHead()
	{
		return Head;
	}

	public void setHead(Elipse head)
	{
		Head = head;
	}

	/*@Override
	public Boolean PointCollision(Integer x, Integer y)
	{
		// TODO Auto-generated method stub
		return super.PointCollision(x, y);
	}*/

	@Override
	public void Print()
	{
		// TODO Auto-generated method stub
		System.out.println("Aktor:  " +
				"Lewa stopa " + LeftLeg.getBeginX() + " " + LeftLeg.getBeginY() + 
				"\nPrawa stopa " + RightLeg.getBeginX() + " " + RightLeg.getBeginY() +
				"\nPepek " + Torso.getBeginX() + " " + Torso.getBeginY() +
				"\nSzyjka " + Torso.getEndX() + " " + Torso.getEndY() +
				"\nGlowa1 " + Head.getFromPoint().getX() + " " + Head.getFromPoint().getY() +
				"\nGlowa2 " + Head.getToPoint().getX() + " " + Head.getToPoint().getY() 
				
				);
	}

	@Override
	public void SetSize(Integer w, Integer h)
	{
		//Integer tmpWidth = x - getPositionX();
		//Integer tmpHeight = y - getPositionY();
		
		LeftLeg.setBeginX(getPositionX() + w*1/6);
		LeftLeg.setBeginY(getPositionY() + h);
		
		RightLeg.setBeginX(getPositionX() + w*5/6);
		RightLeg.setBeginY(getPositionY() + h);
		
		LeftLeg.setEndX(getPositionX() + w/2);
		LeftLeg.setEndY(getPositionY() + h*2/3);
		
		RightLeg.setEndX(getPositionX() + w/2);
		RightLeg.setEndY(getPositionY() + h*2/3);
		
		Torso.setBeginX(getPositionX() + w/2);
		Torso.setBeginY(getPositionY() + h*2/3);
		
		Torso.setEndX(getPositionX() + w/2);
		Torso.setEndY(getPositionY() + h*1/3);
		
		Hands.setBeginX(getPositionX());
		Hands.setBeginY(getPositionY() + h*5/12);
		
		Hands.setEndX(getPositionX()+w);
		Hands.setEndY(getPositionY() + h*5/12);

		
		Head.setFromPoint(new Point(getPositionX() + w*1/6, getPositionY()));
		Head.setToPoint(new Point(getPositionX() + w*5/6, getPositionY() + h*2/6));
		
		Name.setPosition(new Point(getPositionX() + w/2-Name.getCaption().length() *3, 
				new Double(getPositionY() + h + 10+20*(new Double(getHeight().doubleValue()/400.0))).intValue()));
		Name.setTextSize(getHeight() / 10);
		
		//Integer a = 20*(((getHeight().doubleValue()/70.0)).intValue();
		//Integer b = 20*(new Double(getHeight().doubleValue()/70.0).intValue());
		
	}

	@Override
	public void SetTextSize(Integer size)
	{
		// TODO Auto-generated method stub
		Name.setTextSize(size);
	}

	@Override
	public String ToDatabase()
	{
		// TODO Auto-generated method stub
		return super.ToDatabase();
	}

	@Override
	public void MoveByVector(Integer vx, Integer vy)
	{
		
		Name.MoveByVector(vx, vy);
		LeftLeg.MoveByVector(vx, vy);
		RightLeg.MoveByVector(vx, vy);
		Hands.MoveByVector(vx, vy);
		Torso.MoveByVector(vx, vy);
		Head.MoveByVector(vx, vy);
	}
	
	
	
}
